//
//  UpdateDetail.swift
//  DesignCode
//
//  Created by Mithun x on 7/14/19.
//  Copyright © 2019 Mithun. All rights reserved.
//

import SwiftUI

struct ApplyDetail: View {

    var title = "申请详情"
    var image = "Illustration1"
    var applyId = ""
    @State var canEdit = false
    @State var date = ""
    @State var type = ""
    @State var reason = ""
    var personName = ""
    var personId = ""
    @State var status = ""

    var body: some View {
       VStack(spacing: 20.0) {
          Text(title)
             .font(.largeTitle)
             .fontWeight(.heavy)
 
          Image(image)
             .resizable()
             .aspectRatio(contentMode: .fit)
             .frame(height: 200)
 
          Text("编号：\(applyId)")
              .lineLimit(1)
              .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
        HStack {
            Text("时间:")
                  .lineLimit(1)
                  .frame(alignment:  .leading)
            if canEdit {
                TextField("", text: $date)
            } else {
                Text(String(date))
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment:  .leading)
            }
                
        }
        HStack {
            Text("类型：")
                  .lineLimit(1)
                  .frame(alignment:  .leading)
            if canEdit {
                TextField("", text: $type)
            } else {
                Text(String(type))
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment:  .leading)
            }
                
        }
        HStack {
            Text("申请理由：")
                  .lineLimit(1)
                  .frame(alignment:  .leading)
            if canEdit {
                TextField("", text: $reason)
            } else {
                Text(String(reason))
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment:  .leading)
            }
                
        }
//          Spacer
          VStack(spacing: 20.0) {
            Text("申请人：\(personName)")
               .lineLimit(1)
               .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
            Text("申请人编号：\(personId)")
                .lineLimit(1)
                .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
            Text("申请状态：\(status)")
                .lineLimit(1)
                .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
            
          }

          Spacer()
        
        HStack(spacing: 20) {
            Button(action: edit) {
                CircleButton(icon: "pencil")
            }
            Button(action: approve) {
                CircleButton(icon: "person.fill.checkmark")
            }
            Button(action: approve) {
                CircleButton(icon: "delete.right")
            }
        }
       }
       .padding(30.0)
    }
    func edit() -> () {
        self.canEdit.toggle()
    }
    func approve() -> () {
        
    }
    func refuse() -> () {
        
    }
}

#if DEBUG
struct UpdateDetail_Previews: PreviewProvider {
   static var previews: some View {
      ApplyDetail()
   }
}
#endif
